// Supabase 配置
// const SUPABASE_URL = 'https://sbp-9agrjeripewofz3p.supabase.opentrust.net';
// const SUPABASE_ANON_KEY = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoiYW5vbiIsInJlZiI6InNicC05YWdyamVyaXBld29mejNwIiwiaXNzIjoic3VwYWJhc2UiLCJpYXQiOjE3NjExODgxNDMsImV4cCI6MjA3Njc2NDE0M30.pXL3dqVCv8-zZpTsEcH6Q4eWUEbPKZvR8IzMukK66Hw';
// 
const SUPABASE_URL = 'http://192.168.0.210:8000';
const SUPABASE_ANON_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlzcyI6InN1cGFiYXNlIiwiaWF0IjoxNzYxNjY3MjAwLCJleHAiOjI5MTk0MzM2MDB9.T0EGDRqjvHyMtvotUdnFTtzLSC_9VnJZNt3oZtKC6oY';


// const SUPABASE_URL = 'http://42.121.156.106';
// const SUPABASE_ANON_KEY = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJvbGUiOiJhbm9uIiwiaWF0IjoxNzYyMTY3NDkyLCJleHAiOjEzMjcyODA3NDkyfQ.KHdxkgRmc2oYaDK6ahhlBi3qCv-5KLFey3nIZgyng74';

// 安全初始化 Supabase 客户端
let supabase;

function initializeSupabase() {
    try {
        if (typeof window.supabase !== 'undefined' && window.supabase.createClient) {
            supabase = window.supabase.createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
            console.log('✅ Supabase 初始化成功');
            return true;
        } else {
            console.error('❌ Supabase 库未正确加载');
            return false;
        }
    } catch (error) {
        console.error('❌ Supabase 初始化错误:', error);
        return false;
    }
}

// 在页面加载时初始化
document.addEventListener('DOMContentLoaded', function() {
    if (!initializeSupabase()) {
        const messageDiv = document.getElementById('message');
        if (messageDiv) {
            showMessage(messageDiv, 'Supabase 库加载失败，请检查网络连接', 'error');
        }
    }
});